
<!DOCTYPE html>
<html>
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	    <title>菜单分配</title>

         <!-- 所有的 css 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> 
		<link rel="stylesheet" href="../../static/sa.css"> 
		
		<!-- 所有的 js 资源 -->
		<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
		<script src="https://unpkg.com/element-ui@2.8.2/lib/index.js"></script>

		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js"></script>
		<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
		<script src="../../static/sa.js"></script>

        <style>
			body,.el-tree{
				background-color: #F5F5F5;
			}
			.el-tree-node{margin: 0.15em 0 !important;}
		    
			/* 悬浮时颜色更深一点 */
			.el-tree-node__content:hover{background-color: #CFE8FC !important;}
			
        </style>
	
	</head>
	<body>
		
		
		<div class="vue-box">
			
			<!-- 表格 -->
			<div style="padding: 2em;">
				<div class="c-title">所有权限</div>
		        <!-- 此扩展能递归渲染一个权限树，点击深层次节点，父级节点中没有被选中的节点会被自动选中，单独点击父节点，子节点会全部 选中/去选中 -->
				<el-tree
					ref="tree"
					:data="dataList"
					show-checkbox 
					node-key="id"
					:default-expand-all="true"
					:default-checked-keys="select_list" 
					:expand-on-click-node="false"
					:check-on-click-node="true"
					:check-strictly="true"
					@node-click="node_click"
					@check="node_click"
					>
					<span class="custom-tree-node" slot-scope="{ node, data }">
						<span style="color: #2D8CF0;" v-if="data.is_show == undefined || data.is_show == true">{{ data.name }}</span>
						<span style="color: #999;" v-if="data.is_show == false">{{ data.name }} (隐藏)</span>
						<span style="color: #999;" v-if="data.info">&emsp;———— {{data.info}} </span>
					</span>
				</el-tree>

				<!-- 
					default-expand-all  展开所有
					default-checked-keys  默认选中
				 -->

				<br>
				<div class="c-item">
					<label class="c-label" style="width: 1em;"></label>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="ok">确定</el-button>
				</div>
				
	
			</div>
			
			
			
			
		</div>
		
		<script src="../../sa-resources/menu-list.js"></script> 
		<script src="../../sa-resources/admin-util.js"></script>

        <script>
		
			var role_id = sa.$util.getUrlArgs('role_id');
			
			var app = new Vue({
				el: '.vue-box',
				data: {
					dataList: [],	// 数据集合 
					select_list: [],	// 默认选中
				},
				methods: {
					// 保存
					ok: function(){
						var str = '';
						this.$refs.tree.getCheckedKeys().forEach(function(ts){
							str += '&ids=' + ts;
						})
						
						var url = '/MRM/updateRoleMenu?role_id=' + role_id + str;
						sa.ajax2(url,{},function (res) {
							layer.alert('成功', {}, function(){
								if(parent != window){
									parent.layer.closeAll('iframe');
								}
								layer.closeAll();
							});
						})
					},
					// 点击回调, 处理其子节点跟随父节点的选中
					node_click: function(node) {
						var is_select = this.$refs.tree.getCheckedKeys().indexOf(node.id) != -1;	// 此节点现在是否被选中 
						if(node.children){
							node.children.forEach(function(item) {
								this.$refs.tree.setChecked(item.id, is_select);
								// 递归
								if(item.children) {
									this.node_click(item);
								}
							}.bind(this))
						}
					}
				},
				created: function(){
					
					// 全部
					sa.ajax2('/SysMenu/getList', this.p, function(res){
						menuList = arrayToTree(menuList);	// 一维转tree 
						menuList = refMenuList(menuList);	// 属性处理 
						this.dataList = menuList;	// 数据  
						this.select_list = ['11','1', '1-1', '1-2', '1-3', '1-3-1', '2', '2-1', '3', '3-1', '3-2'];	// 选中的列表 
					}.bind(this));
					
					
				}
			})
			
			
			
			
			
			
		
		
		</script>
	
	</body>
</html>